﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using Cesave.DistributedServices.Core.ErrorHandlers;
using Cesave.Domain.PermisosModule.Contracts.Distritos;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.DistributedServices.PermisosModule.Resources;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
		: IPermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="estadoGuid"></param>
		/// <returns></returns>
		public List<Distrito> FindDistritosByEstado(Guid estadoGuid)
		{
			try
			{
				IDistritoService distritoService = IoCFactory.Resolve<IDistritoService>();
				return distritoService.FindDistritosByEstado(estadoGuid);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="estadoGuid"></param>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Distrito> FindDistritosByEstadoAndStatus(Guid estadoGuid, bool status = true)
		{
			try
			{
				IDistritoService distritoService = IoCFactory.Resolve<IDistritoService>();
				return distritoService.FindDistritosByEstadoAndStatus(estadoGuid, status);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distritoGuid"></param>
		/// <returns></returns>
		public Distrito FindDistritoByGuid(Guid distritoGuid)
		{
			try
			{
				IDistritoService distritoService = IoCFactory.Resolve<IDistritoService>();
				return distritoService.FindDistritoByGuid(distritoGuid);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distrito"></param>
		public void AddDistrito(Distrito distrito)
		{
			try
			{
				IDistritoService distritoService = IoCFactory.Resolve<IDistritoService>();
				distritoService.AddDistrito(distrito);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distrito"></param>
		public void ChangeDistrito(Distrito distrito)
		{
			try
			{
				IDistritoService distritoService = IoCFactory.Resolve<IDistritoService>();
				distritoService.ChangeDistrito(distrito);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="distrito"></param>
		public void DeleteDistrito(Distrito distrito)
		{
			try
			{
				IDistritoService distritoService = IoCFactory.Resolve<IDistritoService>();
				distritoService.DeleteDistrito(distrito);
			}
			catch (ArgumentException ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(Messages.exception_InvalidArguments);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}
